package online.chenke.juc;

import java.util.concurrent.CountDownLatch;

/**
 * 10个线程，每个线程加1，加到10
 *
 */
public class Test001 {
	static Integer count = 0;
	
	public static void main(String[] args) throws InterruptedException {
		int n = 10;
		Thread[] threads = new Thread[10];
		CountDownLatch countDownLatch = new CountDownLatch(n);
		
		for (int i = 0; i < n; i++) {
			threads[i] = new Thread(()->{
				synchronized (count) {
					count++;
					System.out.println(Thread.currentThread().getName());
					countDownLatch.countDown();
				}
				
			}, "t"+i);
		}
		
		for(int i = 0; i < n; i++) {
			threads[i].start();
		}
		
		countDownLatch.await();
		System.out.println(count);
	}
}
